<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>根据先序遍历和中序遍历建立二叉树 | 博客主页 | 世界是个球，前方总有路！</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="数据结构与算法">
    <meta name="description" content="问题​    已知一棵二叉树的先序遍历以及中序遍历，重建二叉树。二叉树的每一个节点有三个属性，左子节点，右子节点，以及节点值。    思路先序遍历服从规则“根左右”，所以由此可知，对于一个先序遍历得到的数组，第一个元素一定是根节点； 中序遍历服从规则”左根右“，所以由此可知，对于一个中序遍历得到的数组，根节点左边的元素都属于根节点的左子树，而根节点右边的元素都属于根节点的右子树； 所以，我们可以先">
<meta property="og:type" content="article">
<meta property="og:title" content="根据先序遍历和中序遍历建立二叉树">
<meta property="og:url" content="http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/index.html">
<meta property="og:site_name" content="博客主页">
<meta property="og:description" content="问题​    已知一棵二叉树的先序遍历以及中序遍历，重建二叉树。二叉树的每一个节点有三个属性，左子节点，右子节点，以及节点值。    思路先序遍历服从规则“根左右”，所以由此可知，对于一个先序遍历得到的数组，第一个元素一定是根节点； 中序遍历服从规则”左根右“，所以由此可知，对于一个中序遍历得到的数组，根节点左边的元素都属于根节点的左子树，而根节点右边的元素都属于根节点的右子树； 所以，我们可以先">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-07-23T14:37:34.000Z">
<meta property="article:modified_time" content="2019-10-10T05:23:50.161Z">
<meta property="article:author" content="特务依昂">
<meta property="article:tag" content="数据结构与算法">
<meta name="twitter:card" content="summary">
    
        <link rel="alternate" type="application/atom+xml" title="博客主页" href="/blog/atom.xml">
    
    <link rel="shortcut icon" href="/blog/img/title.png">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/blog/img/brand.jpg)">
      <div class="brand">
        <a href="/blog/" class="avatar waves-effect waves-circle waves-light">
          <img src="/blog/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">特务依昂</h5>
          <a href="mailto:1131564805@qq.com" title="1131564805@qq.com" class="mail">1131564805@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/blog/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                博客
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/tewuyiang" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://weibo.com/u/5516635708/" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                Weibo
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://www.cnblogs.com/tuyang1129/" target="_blank" >
                <i class="icon icon-lg icon-link"></i>
                博客园
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">根据先序遍历和中序遍历建立二叉树</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">根据先序遍历和中序遍历建立二叉树</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-07-23T14:37:34.000Z" itemprop="datePublished" class="page-time">
  2019-07-23
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/blog/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/">数据结构与算法</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#问题"><span class="post-toc-number">1.</span> <span class="post-toc-text">问题</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#思路"><span class="post-toc-number">2.</span> <span class="post-toc-text">思路</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#例子"><span class="post-toc-number">3.</span> <span class="post-toc-text">例子</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#代码"><span class="post-toc-number">4.</span> <span class="post-toc-text">代码</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#树的节点"><span class="post-toc-number">4.0.1.</span> <span class="post-toc-text">树的节点</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#建树方法"><span class="post-toc-number">4.0.2.</span> <span class="post-toc-text">建树方法</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#建树代码（优化）"><span class="post-toc-number">4.0.3.</span> <span class="post-toc-text">建树代码（优化）</span></a></li></ol></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-根据先序遍历和中序遍历建立二叉树"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">根据先序遍历和中序遍历建立二叉树</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-07-23 22:37:34" datetime="2019-07-23T14:37:34.000Z"  itemprop="datePublished">2019-07-23</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/blog/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/">数据结构与算法</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>​    已知一棵二叉树的先序遍历以及中序遍历，重建二叉树。二叉树的每一个节点有三个属性，左子节点，右子节点，以及节点值。   </p>
<h2 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h2><p>先序遍历服从规则<strong>“根左右”</strong>，所以由此可知，对于一个先序遍历得到的数组，第一个元素一定是<strong>根节点</strong>；</p>
<p>中序遍历服从规则<strong>”左根右“</strong>，所以由此可知，对于一个中序遍历得到的数组，根节点左边的元素都属于根节点的<strong>左子树</strong>，而根节点右边的元素都属于根节点的<strong>右子树</strong>；</p>
<p>所以，我们可以先通过先序遍历的第一个元素确定根节点，然后通过中序遍历结合根节点，获得当前根节点的左右子树，再将子树看成一棵独立的树，继续使用先序遍历判断根节点，中序遍历判断子树的方式，最终建立起整棵树；</p>
<h2 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h2><p>假设有一棵二叉树，先序遍历为<strong>{1,2,4,7,3,5,6,8}</strong>，中序遍历为<strong>{4,7,2,1,5,3,8,6}</strong>，则建树过程如下：</p>
<blockquote>
<p>首先，通过先序遍历可知树的根节点为<strong><em>1</em></strong>，则在中序遍历中，1左边的元素<strong><em>4，7，2</em></strong>即为根的左子树的元素，而<strong><em>1</em></strong>右边的元素<strong><em>5，3，8，6</em></strong>即为根节点的右子树；</p>
<blockquote>
<p>对于左子树<strong><em>4，7，2</em></strong>来说，在先序遍历中，这三个点的顺序为<strong><em>2，4，7</em></strong>，则<strong><em>2</em></strong>为根节点，而在中序遍历中，<strong><em>4，7</em></strong>均在<strong><em>2</em></strong>的左边，则<strong><em>4，7</em></strong>均为以<strong><em>2</em></strong>为根树的左子树，且没有右子树；</p>
<blockquote>
<p>对于<strong><em>4，7</em></strong>这两个节点来说，先序遍历中，<strong><em>4</em></strong>节点在7节点之前，所以<strong><em>4</em></strong>为根节点，而<strong><em>7</em></strong>作为子树，在中序遍历中，<strong><em>7</em></strong>在<strong><em>4</em></strong>之后，所以<strong><em>7</em></strong>为右子树；</p>
</blockquote>
</blockquote>
<blockquote>
<p>对于根节点<strong><em>1</em></strong>的右子树<strong><em>5，3，8，6</em></strong>来说，在先序遍历中，<strong><em>3</em></strong>在最前面，所以<strong><em>3</em></strong>为这棵子树的根节点，而在中序遍历中，<strong><em>5</em></strong>在<strong><em>3</em></strong>的左边，所以属于左子树，而<strong><em>8，6</em></strong>在<strong><em>3</em></strong>的右边，属于右子树；</p>
<blockquote>
<p>对于根节点<strong><em>3</em></strong>的右子树<strong><em>8，6</em></strong>，在先序遍历中，<strong><em>6</em></strong>在<strong><em>8</em></strong>之前，所以，<strong><em>6</em></strong>又为根节点，而在中序遍历中，<strong><em>8</em></strong>在<strong><em>6</em></strong>的左边，所以<strong><em>8</em></strong>是<strong><em>6</em></strong>的左子节点；</p>
</blockquote>
</blockquote>
</blockquote>
<p>至此，二叉树便重建完成；</p>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><h4 id="树的节点"><a href="#树的节点" class="headerlink" title="树的节点"></a>树的节点</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TreeNode</span> </span>&#123;</span><br><span class="line">	<span class="keyword">int</span> val;		<span class="comment">//当前节点的值</span></span><br><span class="line">	TreeNode left;	<span class="comment">//左子节点</span></span><br><span class="line">	TreeNode right;	<span class="comment">//右子节点</span></span><br><span class="line"></span><br><span class="line">	TreeNode(<span class="keyword">int</span> x) &#123;</span><br><span class="line">		val = x;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="建树方法"><a href="#建树方法" class="headerlink" title="建树方法"></a>建树方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* pre：线序遍历得到的数组</span></span><br><span class="line"><span class="comment">* in：中序遍历得到的数组</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> TreeNode <span class="title">reConstructBinaryTree</span><span class="params">(<span class="keyword">int</span>[] pre, <span class="keyword">int</span>[] in)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(pre.length == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> root = pre[<span class="number">0</span>];</span><br><span class="line">    TreeNode node = <span class="keyword">new</span> TreeNode(root);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//寻找根节点在in中的索引</span></span><br><span class="line">    <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>( ; i&lt;in.length; ++i) &#123;</span><br><span class="line">        <span class="keyword">if</span>(in[i] == root) &#123;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//建立左子树</span></span><br><span class="line">    <span class="keyword">int</span>[] leftIn = Arrays.copyOfRange(in, <span class="number">0</span>, i);</span><br><span class="line">    <span class="keyword">int</span>[] leftPre = Arrays.copyOfRange(pre, <span class="number">1</span>, i+<span class="number">1</span>);</span><br><span class="line">    node.left = reConstructBinaryTree(leftPre, leftIn);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//建立右子树</span></span><br><span class="line">    <span class="keyword">int</span>[] rightIn = Arrays.copyOfRange(in, i+<span class="number">1</span>, in.length);</span><br><span class="line">    <span class="keyword">int</span>[] rightPre = Arrays.copyOfRange(pre, i+<span class="number">1</span>, pre.length);</span><br><span class="line">    node.right = reConstructBinaryTree(rightPre, rightIn);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> node;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="建树代码（优化）"><a href="#建树代码（优化）" class="headerlink" title="建树代码（优化）"></a>建树代码（优化）</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> TreeNode <span class="title">reConstructBinaryTree</span><span class="params">(<span class="keyword">int</span>[] pre, <span class="keyword">int</span>[] in)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> getRootTreeNode(pre, <span class="number">0</span>, pre.length-<span class="number">1</span>, in, <span class="number">0</span>, in.length-<span class="number">1</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* preL：当前子树在先序遍历的数组中的起始下标</span></span><br><span class="line"><span class="comment">* preR：当前子树在先序遍历的数组中的结束下标</span></span><br><span class="line"><span class="comment">* inL：当前子树在中序遍历的数组中的起始下标</span></span><br><span class="line"><span class="comment">* inR：当前子树在中序遍历的数组中的起始下标</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> TreeNode <span class="title">getRootTreeNode</span><span class="params">(<span class="keyword">int</span>[] pre, <span class="keyword">int</span> preL, </span></span></span><br><span class="line"><span class="function"><span class="params">                                <span class="keyword">int</span> preR, <span class="keyword">int</span>[] in, <span class="keyword">int</span> inL, <span class="keyword">int</span> inR)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(preL &gt; preR) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    TreeNode node = <span class="keyword">new</span> TreeNode(pre[preL]);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=inL; i&lt;=inR; ++i) &#123;</span><br><span class="line">        <span class="keyword">if</span>(in[i] == pre[preL]) &#123;</span><br><span class="line"></span><br><span class="line">            node.left = getRootTreeNode(pre, preL+<span class="number">1</span>, preL+i-inL, in, inL, i-<span class="number">1</span>);</span><br><span class="line">            node.right = getRootTreeNode(pre, preL+i-inL+<span class="number">1</span>, preR, in, i+<span class="number">1</span>, inR);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> node;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2019-10-10T05:23:50.161Z" itemprop="dateUpdated">2019-10-10 13:23:50</time>
</span><br>


        
        世界是个球，前方总有路！
        
    </div>
    
    <footer>
        <a href="http://tewuyiang.gitee.io/blog">
            <img src="/blog/img/avatar.jpg" alt="特务依昂">
            特务依昂
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/" rel="tag">数据结构与算法</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&title=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&pic=http://tewuyiang.gitee.io/blog/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&title=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&source=一个未来程序员的博客~~~" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&via=http://tewuyiang.gitee.io/blog" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/blog/HttpServlet%E4%B8%ADservice%E6%96%B9%E6%B3%95%E6%BA%90%E7%A0%81%E8%A7%A3%E8%AF%BB/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">HttpServlet中service方法的源码分析</h4>
      </a>
    </div>
  

  
</nav>



    




















</article>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/blog/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>特务依昂 &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&title=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&pic=http://tewuyiang.gitee.io/blog/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&title=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&source=一个未来程序员的博客~~~" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《根据先序遍历和中序遍历建立二叉树》 — 博客主页&url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/&via=http://tewuyiang.gitee.io/blog" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://tewuyiang.gitee.io/blog/%E6%A0%B9%E6%8D%AE%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BB%BA%E7%AB%8B%E4%BA%8C%E5%8F%89%E6%A0%91/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/blog/', SHARE: true, REWARD: false };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '人呢，怎么不见了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!欢迎回来!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
